package com.atguigu.gulimall.order.service.impl;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;


@RabbitListener(queues = {"hello-java-queue"})
@Service
public class MyRabbitMQServiceImpl {

    @RabbitHandler
    public void recieveMessage(Message message,
                               OrderReturnReasonEntity returnReasonEntity,
                               Channel channel) throws IOException {
        System.out.println("接收到的消息。。。" + returnReasonEntity);
        System.out.println("消息处理完成" + returnReasonEntity.getName());
        // 手动 ack
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        channel.basicAck(deliveryTag, false);

    }

    @RabbitHandler
    public void recieveMessage2(Message message,
                                OrderEntity orderEntity,
                                Channel channel) throws IOException {
        System.out.println("接收到的消息recieveMessage2。。。" + orderEntity);
        System.out.println("消息处理完成recieveMessage2" + orderEntity.getOrderSn());
        // 手动 ack
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        channel.basicAck(deliveryTag, false);
    }
}
